var jwt = require('jsonwebtoken');
module.exports=()=>
{
    return async (ctx,next)=>
    {
        let widthpath=['/login','/gai']
      if( widthpath.includes(ctx.path)) 
      {
          await next()
      }else{
          try {
           jwt.verify(ctx.headers.token, 'secret');
           await next()
          } catch (error) {
            if(error.name=='TokenExpiredError')
            {
                ctx.status=401
                await next()
            }
          }
      }

    }
}